package com.codemonkey.lq.qd.builder.xml;

import org.apache.ibatis.parsing.XNode;

import com.codemonkey.lq.qd.builder.BaseBuilder;
import com.codemonkey.lq.qd.facotry.config.AbstractFlowDefinition;
import com.codemonkey.lq.qd.facotry.config.AbstractServiceDefinition;
import com.codemonkey.lq.qd.facotry.config.SConfiguration;
import com.codemonkey.lq.qd.facotry.support.GenericFlowDefinition;
import com.codemonkey.lq.qd.utils.XNodeUtils;

/**
 * @author LQ
 */
public class XMLFlowBuilder extends BaseBuilder {
	private XNode context;
	private final AbstractServiceDefinition sd;

	public XMLFlowBuilder(XNode context, AbstractServiceDefinition sd, SConfiguration configuration) {
		super(configuration);
		this.context = context;
		this.sd = sd;
	}

	@Override
	protected Object doParse() {
		String from = context.getStringAttribute("from");
		String to = context.getStringAttribute("to");
		String condition = XNodeUtils.getStrBody(context);

		AbstractFlowDefinition sf = new GenericFlowDefinition();
		sf.setFrom(from);
		sf.setTo(to);
		sf.setCondition(condition);

		sd.addFlow(sf);
		
		return sf;
	}
}
